//
//  CredentialsViewController.m
//  Conference
//
//  Created by 陈鑫 on 12-11-16.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "CredentialsViewController.h"
#import "AppDelegate.h"
#import "Member.h"
#import "QRCodeGenerator.h"
#import "NetContant.h"
#import "Globals.h"
#import "Constant.h"
#import "WebData.h"
@interface CredentialsViewController ()

@end

@implementation CredentialsViewController
@synthesize lab_company_name;
@synthesize img_2DCode;
@synthesize lab_name;
@synthesize lab_username;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    Member *member=[(AppDelegate *)[[UIApplication sharedApplication] delegate]userMember];
    self.lab_name.text=member.firstName;
    self.lab_company_name.text=member.companyName;
    self.lab_username.text=member.phone;
    
    
    NSThread *thread=[[[NSThread alloc] initWithTarget:self selector:@selector(run) object:nil] autorelease];
    [thread start];
  
    // Do any additional setup after loading the view from its nib.
}
-(void)run{
    NSAutoreleasePool *pool=[[NSAutoreleasePool alloc] init];
    NSString *sRet=[[WebData getInstance]getEleInfo];
        [self performSelectorOnMainThread:@selector(onPostExecute:) withObject:sRet waitUntilDone:YES];
	[pool release];
    
}
-(void)onPostExecute:(NSString *)sRet{
    
    if ([sRet isEqualToString:[[NetContant getInstance] NET_CONNECT_FALSE]]) {
        
        
       [[Globals getInstance] showAlertView:[[Constant getInstance] net_error]];
        
        
    }else if([sRet isEqualToString:[[NetContant getInstance] NETWORK_RECORD_ISEMPTY]]){
        
        // [[Globals getInstance] showAlertView:[[Constant getInstance] data_isempty]];
        
    }else {
        @try {
            UIImage*image=[QRCodeGenerator qrImageForString:sRet imageSize:self.img_2DCode.bounds.size.width];
            self.img_2DCode.image=image;
        }
        @catch (NSException *exception) {
            //
        }
        
        
    }
    
}

- (void)viewDidUnload
{
    [self setLab_name:nil];
    [self setLab_company_name:nil];
    [self setLab_username:nil];
    [self setImg_2DCode:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (void)dealloc {
    [lab_name release];
    [lab_company_name release];
    [lab_username release];
    [img_2DCode release];
    [super dealloc];
}
@end
